{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox-title">
        <h5>添加奖品</h5>
    </div>
    <div class="ibox-content layui-form">
        <div class="layui-row layui-col-space10 layui-form-item ">
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                <label class="layui-form-label">奖品类型：</label>
                <div class="layui-input-block">
                    <select name="type" lay-verify="required" lay-search="" lay-filter="type">
                        <option value="">请选择奖品类型</option>
                        <option value="1" >积分</option>
                        <option value="2" >实物</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8" style="display: none;" id="goods">
                <label class="layui-form-label">实物奖品：</label>
                <div class="layui-input-block">
                    <select name="goods" lay-search="" lay-verify="required" lay-filter="goods" id="goods1">
                        <option  value="">选择实物奖品</option>
                        {foreach name="$goods" item="vo"}
                        <option  value="{$vo.p_id}">{$vo.p_name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8" style="display: none" id="jifen">
                <label class="layui-form-label">积分数量：</label>
                <div class="layui-input-block">
                    <input type="text" name="jifen" lay-verify="required" id="number" placeholder="积分数量" class="layui-input layui-disabled" value="1" oninput="value=value.replace(/[^\d]/g,'')" disabled>
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                <label class="layui-form-label">第几天：</label>
                <div class="layui-input-block">
                    <input type="text" name="day" lay-verify="required" placeholder="第几天" class="layui-input" oninput="value=value.replace(/[^\d]/g,'')">
                </div>
            </div>
            <!--<div class="layui-form-item layui-col-md-offset1 layui-col-md8">-->
                <!--<label class="layui-form-label">奖品名：</label>-->
                <!--<div class="layui-input-block">-->
                    <!--<input type="text" name="name" lay-verify="required|username" placeholder="奖品名称" class="layui-input ">-->
                <!--</div>-->
            <!--</div>-->
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                    </button>
                    <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">返回</button>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form'], function() {
        var form = layui.form;
        form.on('select(type)', function(data){
            if(data.value == 1){
                $('#jifen').show();
                $('#number').attr('lay-verify','required');
                $('#goods').hide();
                $('#goods1').attr('lay-verify','');
            }else if(data.value == 2){
                $('#jifen').hide();
                $('#number').attr('lay-verify','');
                $('#goods').show();
                $('#goods1').attr('lay-verify','required');
            }
        });
        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('signAdd')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('sign/index')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
    });
</script>
</body>
</html>